<#--
  Controller 标准 CRUD 接口方法
-->

    @Operation(summary = "分页查询${table.comment!table.entityName}")
    @RequiresPermission("${permissionPrefix}:list")
    @GetMapping
    public Result<PageResponse<${table.entityName}DTO>> list(${table.entityName}DTO queryDTO) {
        PageResponse<${table.entityName}DTO> page = ${lowerEntity}Service.queryPage(queryDTO);
        return Result.success(page);
    }

    @Operation(summary = "查询${table.comment!table.entityName}详情")
    @RequiresPermission("${permissionPrefix}:detail")
    @GetMapping("/{id}")
    public Result<${table.entityName}DTO> detail(@PathVariable ${pkType} id) {
        ${table.entityName}DTO dto = ${lowerEntity}Service.getDetail(id);
        return Result.success(dto);
    }

    @Operation(summary = "新增${table.comment!table.entityName}")
    @RequiresPermission("${permissionPrefix}:add")
    @PostMapping
    public Result<${table.entityName}DTO> add(@Valid @RequestBody ${table.entityName}DTO dto) {
        ${table.entityName}DTO result = ${lowerEntity}Service.create(dto);
        return Result.success(result);
    }

    @Operation(summary = "修改${table.comment!table.entityName}")
    @RequiresPermission("${permissionPrefix}:edit")
    @PutMapping("/{id}")
    public Result<${table.entityName}DTO> edit(@PathVariable ${pkType} id, @Valid @RequestBody ${table.entityName}DTO dto) {
        ${table.entityName}DTO result = ${lowerEntity}Service.update(id, dto);
        return Result.success(result);
    }

    @Operation(summary = "删除${table.comment!table.entityName}")
    @RequiresPermission("${permissionPrefix}:remove")
    @DeleteMapping("/{id}")
    public Result<Void> remove(@PathVariable ${pkType} id) {
        ${lowerEntity}Service.deleteById(id);
        return Result.success();
    }

    @Operation(summary = "批量删除${table.comment!table.entityName}")
    @RequiresPermission("${permissionPrefix}:remove")
    @DeleteMapping("/batch")
    public Result<Void> batchDelete(@RequestBody List<${pkType}> ids) {
        ${lowerEntity}Service.deleteBatch(ids);
        return Result.success();
    }

    @Operation(summary = "导出${table.comment!table.entityName}")
    @RequiresPermission("${permissionPrefix}:export")
    @PostMapping("/export")
    public void export(@RequestBody ${table.entityName}DTO queryDTO, HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        String fileName = java.net.URLEncoder.encode("${table.comment!table.entityName}列表", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        
        ${lowerEntity}Service.exportData(queryDTO, response.getOutputStream());
    }

    @Operation(summary = "导入${table.comment!table.entityName}")
    @RequiresPermission("${permissionPrefix}:import")
    @PostMapping("/import")
    public Result<java.util.Map<String, Object>> importData(
            @RequestParam("file") MultipartFile file,
            @RequestParam(value = "updateSupport", defaultValue = "false") boolean updateSupport) throws IOException {
        java.util.Map<String, Object> result = ${lowerEntity}Service.importData(file.getInputStream(), updateSupport);
        return Result.success(result);
    }

    @Operation(summary = "下载${table.comment!table.entityName}导入模板")
    @RequiresPermission("${permissionPrefix}:import")
    @GetMapping("/template")
    public void downloadTemplate(HttpServletResponse response) throws IOException {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        String fileName = java.net.URLEncoder.encode("${table.comment!table.entityName}导入模板", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        
        ${lowerEntity}Service.downloadImportTemplate(response.getOutputStream());
    }


